﻿namespace Furesoft.Styling.Converters
{
    using System.Drawing;

    internal class ColorConverter : IConverter<Color>
    {
        #region Public Methods and Operators

        public override Color Convert(string s)
        {
            if (s.StartsWith("#"))
            {
                return ColorTranslator.FromHtml(s);
            }
            if (Function.IsFunction(s))
            {
                Function f = Function.Parse(s);
                return (Color)Function.ResolveClrFunc(new Functions.ColorFunctions(), f);
            }
            else if (s != "")
            {
                return Color.FromName(s);
            }
            return default(Color);
        }

        public override string Convert(Color s)
        {
            return ColorTranslator.ToHtml(s);
        }

        #endregion
    }
}